﻿using System;
using System.ComponentModel;
using System.Reflection;
using UtfprLibrary.Windows.Forms.ComponentModel;
using UtfprLibrary.Windows.Forms.Exceptions;

namespace UtfprLibrary.Windows.Forms.Helpers {
    /// <summary>
    /// TODO
    /// </summary>
    public class StateHelper {
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string GetDescription(UBNStateEnum state) {
            try {
                Type type = state.GetType();

                MemberInfo info = state.GetType();

                if (info != null) {
                    object[] attrs = info.GetCustomAttributes(
                        typeof(DescriptionAttribute), false);

                    if (attrs != null && attrs.Length > 0) {
                        return ((DescriptionAttribute)attrs[0]).Description;
                    }
                }

                return state.ToString();
            } catch (Exception ex) {
                throw new UtfprWFCoreHelpersException("", ex);
            }
        }
    }
}

